<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>房屋交易管理</title>
  <link rel="shortcut icon" href="../../favicon.ico">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  <link rel="stylesheet" href="../../styles/common.css">
  <link rel="stylesheet" href="../../styles/login.css">
  <link rel="stylesheet" href="../../styles/icon/iconfont.css" />
  <style>
    .body{
      min-width: 1366px;
    }
  </style>
</head>

<body>
<div class="login" id="login-app">
  <div class="login-box">
    <img src="../../images/login/login.png" alt="">
    <div class="login-form">
      <el-form ref="loginForm" :model="regiteForm" :rules="regiteRules" >
        <div class="login-form-title">
          <p style="color:orange;font-size:20px;">房屋交易管理系统</p>
        </div>
        <el-form-item prop="name">
          <el-input v-model="regiteForm.name" type="text" auto-complete="off" placeholder="姓名" maxlength="20"
                    prefix-icon="iconfont icon-user"/>
        </el-form-item>
        <el-form-item prop="password">
          <el-input v-model="regiteForm.password" type="password" placeholder="密码" prefix-icon="iconfont icon-lock" maxlength="20"/>
        </el-form-item>
        <el-form-item prop="sex"  label="性别">
          <el-radio-group v-model="regiteForm.sex">
            <el-radio label="1">男</el-radio>
            <el-radio label="0">女</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item prop="phone">
          <el-input v-model="regiteForm.phone" type="text" auto-complete="off" placeholder="手机号" maxlength="11"/>
        </el-form-item>
        <el-form-item style="width:100%;">
          <el-button :loading="registing" class="regist-btn" size="medium" type="primary" style="width:100%;"
                     @click.native.prevent="handleRegister">
            <span v-if="!registing">注册</span>
            <span v-else>注册...</span>
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</div>

<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../js/validate.js"></script>
<script src="../../api/login.js"></script>

<script>
  new Vue({
    el: '#login-app',
    data() {
      return {
        regiteForm:{
          name:'小王',
          password: '123456',
          sex:'1',
          phone:'12345678898',
        },
        registing:false
      }
    },
    computed: {
      regiteRules() {
        const validateName = (rule, value, callback) => {
          if (value.length < 1 ) {
            callback(new Error('请输入姓名'))
          } else {
            callback()
          }
        }
        const validatePassword = (rule, value, callback) => {
          if (value.length < 6) {
            callback(new Error('密码必须在6位以上'))
          } else {
            callback()
          }
        }
        const validateSex= (rule, value, callback) => {
          if (value.length < 1 ) {
            callback(new Error('性别不能为空'))
          } else {
            callback()
          }
        }
        const validatePhone = (rule, value, callback) => {
          if (value.length != 11) {
            callback(new Error('请确认手机号码是否正确'))
          } else {
            callback()
          }
        }
        return {
          'name': [{ 'validator': validateName, 'trigger': 'blur' }],
          'password': [{ 'validator': validatePassword, 'trigger': 'blur' }],
          'sex': [{ 'validator': validateSex, 'trigger': 'blur' }],
          'phone': [{ 'validator': validatePhone, 'trigger': 'blur' }]
        }
      }
    },
    created() {
    },
    methods: {
      async handleRegister() {
        this.$refs.loginForm.validate(async (valid) => {
          if (valid) {
            this.registing = true
            let res = await registeApi(this.regiteForm)
            console.log("这里")
            console.log(res)
            if (String(res.code) === '1') {
              // localStorage.setItem('userInfo',JSON.stringify(res.data))
              window.location.href= '/backend/page/login/login.html'
            } else {
              this.$message.error(res.msg)
              this.registing = false
            }
          }
        })
      },

    }
  })
</script>
</body>

</html>
